package cn.stylefeng.guns.modular.robot.cmd.abs;

import cn.stylefeng.guns.modular.robot.cmd.Cmd;
import org.apache.commons.lang3.StringUtils;
import org.telegram.telegrambots.bots.TelegramLongPollingBot;
import org.telegram.telegrambots.meta.api.objects.Update;

import java.util.Arrays;
import java.util.List;
import java.util.Locale;

public abstract class AbstractCmd implements Cmd {

    private List<String> cmdMediaNames = Arrays.asList("/PHOTO", "/AUDIO", "/VIDEO");

    public void execCmd(Update update, TelegramLongPollingBot bot) {
        String cmdName = getCmdName();
        String text = update.getMessage().getText();
        if (StringUtils.isBlank(text)) {
            if (cmdMediaNames.contains(cmdName)) {
                exec(update, bot);
            }
            return;
        }
        if (text.toUpperCase(Locale.ROOT).startsWith(cmdName)) {
            exec(update, bot);
            return;
        }
        if (!"+下发".equals(cmdName)) {
            return;
        }
        if (text.startsWith("+") || text.startsWith("下发")) {
            exec(update, bot);
        }
    }
}
